package org.evan.spring.validator.four;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import jakarta.validation.ConstraintViolation;

public class CannotBlankValidator implements ConstraintValidator<CannotBlank,String> {
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(value == null || value.contains(" ")){
            String s = context.getDefaultConstraintMessageTemplate();
            System.out.println("default message = " + s);
            context.disableDefaultConstraintViolation();
            context.buildConstraintViolationWithTemplate("can not constrains blank").addConstraintViolation();
            return false;
        }
        return false;
    }
}
